
// keep track of the id of the dynamic div that is open 
var opendiv = "";
// keep track of form submit status
var submited = false;
// keep track of window size
var myWidth = 0, myHeight = 0;
// variable to keep dynamically loaded images
var myImage = new Image;

// Ajax variables
// function to run on ajax return
var AjaxReturnFunc;
var AjaxURL;
var AjaxPostBody;
var miscglobal1;
var miscglobal2;
var miscglobal3;
var miscglobal4;

// expand a dynamic div by using its id
// check for it already being open and close
function expanddiv(id, oldid) {

	document.getElementById('newdomainres').style.display = 'none';
	document.getElementById('transferdomainres').style.display = 'none';

	var e = document.getElementById(id);
	var useglobalopendiv = 0;
	if(oldid == undefined) {
		oldid = opendiv;
		useglobalopendiv = 1;
		// if not give use the global variable
	}
	
	// close already open div
	if(oldid != '' && oldid != id) {
		var o = document.getElementById(oldid);
		if(o)
			Effect.SlideUp(o);
	}

	// open new div
	if(e && oldid != id) {
		if(useglobalopendiv)
			opendiv = id;
		else
			oldid = id;
	Effect.SlideDown(e);
	}
}


// disable enter key or use a different function when enter is pressed
function disableEnterKey(e, func) {
	var key;
	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = e.which;     //firefox
	if(key == 13) {
		if(func != '')
			func();
		return false;
	} else {
		return true;
	}
}

function LookupNewDomain(resultdiv, loadingimageid, loadingimagesrc, extra) {
	AjaxURL = '/c/spincheck.php';
	var dom = document.getElementById('thsld').value;
	var tld = document.getElementById('thtld')[document.getElementById('thtld').selectedIndex].text;
	if(dom.length<2) {
		alert("Lütfen bir alan adý giriniz");
		return false;
	}
	if(tld == '')
		tld = 'com';

	AjaxReturnFunc = function(t) {
		var div = document.getElementById(resultdiv);
		div.innerHTML = t.responseText;
		Effect.SlideDown(div);
		if(loadingimageid != undefined && loadingimagesrc != undefined)
			document.getElementById(loadingimageid).src = '/template/images/spacer.gif';
		submited = false;
		return false;
	}
	AjaxPostBody = {method:'post', postBody:'cSSld=' + dom + '&ttld[]=' + tld + '&action=check&subaction=hwizard&resultonly=1'+extra, onSuccess:AjaxReturnFunc, onFailure:AjaxReturnFunc};

	if(submited != false) {
		return false;
	} else {
		submited = true;
	}
	if(loadingimageid != undefined && loadingimagesrc != undefined)
		document.getElementById(loadingimageid).src = loadingimagesrc;

	var div = document.getElementById(resultdiv);
	if(div.style.display != 'none') {
		Effect.SlideUp(div);
		setTimeout('callAjax()', 1000);
	} else {
		callAjax();
	}

	return false;
}

function LookupTransferDomain(resultdiv, loadingimageid, loadingimagesrc, extra) {
	AjaxURL = '/c/tspincheck.php';
	var dom = document.getElementById('mhsld').value;
	var mhtld = document.getElementById('mhtld');
	var tld = mhtld.options[mhtld.selectedIndex].text;
	if(tld == '')
		tld = 'com';
	if(dom.length<2) {
		alert("Lütfen bir alan adý giriniz");
		return false;
	}

	AjaxReturnFunc = function(t) {
		var div = document.getElementById(resultdiv);
//		alert(t.responseText + '\ndiv:' + resultdiv + '\nimg:' + loadingimageid + '\nimg:' + document.getElementById(loadingimageid).src);
//		var newdiv = document.createElement("div");
		div.innerHTML = t.responseText;
//		div.appendChild(newdiv);
		Effect.SlideDown(div);
//alert('3');
		if(loadingimageid != undefined && loadingimagesrc != undefined) {
			document.getElementById(loadingimageid).src = '/template/images/spacer.gif';
//alert('in image change');
		}
		submited = false;
		return false;
	}
	AjaxPostBody = {method:'post', postBody:'check1=' + dom + '&tld1=' + tld + '&action=check&subaction=hwizard&resultonly=1'+extra, onSuccess:AjaxReturnFunc, onFailure:AjaxReturnFunc};

	if(submited != false) {
		return false;
	} else {
		submited = true;
	}
	if(loadingimageid != undefined && loadingimagesrc != undefined)
		document.getElementById(loadingimageid).src = loadingimagesrc;

	var div = document.getElementById(resultdiv);
	if(div.style.display != 'none') {
		Effect.SlideUp(div);
		setTimeout('callAjax()', 1000);
	} else {
		callAjax();
	}

	return false;
}

function callAjax() {
	new Ajax.Request(AjaxURL, AjaxPostBody);
}

function strValidate(checkStr,type){
	if (type == "t")
		var checkOK = "\r\nABCDEFGHIJKLMNOPQRSTUVWXYZöçsigüÖÇSIGÜabcdefghijklmnopqrstuvwxyz0123456789-',.\"!@#$%*)(_+?:}{[]/\\\~| ";
	else
		var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.";

	
	var allValid = 0;
	
	for (i = 0;  i < checkStr.length;  i++){
		
		ch = checkStr.charAt(i);

		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
			
			if (j == checkOK.length){
				allValid = 1;
				break;
			}
	}
	return allValid;
}


// This function is no longer used and has been replaced by the lightbox package
function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
//	  alert('dark no found');
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';                          
  } else {
     dark.style.display='none';
  }
}

// This function is no longer used and has been replaced by the lightbox package
function displayPopUpImage(imageurl) {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	grayOut(true); 

	var e = document.getElementById('abovealldiv');
	e.style.top = (myHeight/2) - 10 + 'px';
	e.style.left = (myWidth/2) - 10 + 'px';
	e.style.display = 'block';
	e.innerHTML = '<img src=\'/template/images/loadingcircle_black_graybg.gif\'>';

	myImage = new Image;
	myImage.src = imageurl;
	myImage.onload = updatePopUpImage;
}

// This function is no longer used and has been replaced by the lightbox package
function updatePopUpImage() {
	var e = document.getElementById('abovealldiv');
	y = (myHeight/2) - (myImage.height/2);
	if(y<10) e.style.top = '10px'; else e.style.top = y + 'px';
	x = (myWidth/2) - (myImage.width/2);
	if(x<10) e.style.left = '10px'; else e.style.left = x + 'px';
//	alert('h='+myHeight+' y='+y+' w='+myWidth+' x='+x);
	e.style.zIndex = 99;
	e.innerHTML = '<a href=\"#\" onclick=\"document.getElementById(\'abovealldiv\').style.display = \'none\'; grayOut(false); return false;\"><img border=0 src=\'' + myImage.src + '\'></a>';	
	e.style.display = 'block';
}

//Kazim Ekledi...

function createObject() {
	var object;
	var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			object = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			object = new XMLHttpRequest();
		}
	return object;
}
	var http = createObject();

function doIt(div,func,value1,value2){
	divid = div;
	http.open('get', '/call.php?function='+func+'&value1=' + value1 + '&Title='+value2);
	http.onreadystatechange = Response;
	http.send(null);
}

function doItP(div,func,value1,value2){
	divid = div;
//	http.open('get', '/call.php');
//	http.onreadystatechange = Response;
//	http.send(null);

	var datax = 'function='+func+'&value1=' + value1 + '&Title='+value2;
	http.open('POST', '/call.php');
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-9");
	http.onreadystatechange = Response;
	http.send(datax);

}

function Response() {
	if(http.readyState == 4){
		document.getElementById(divid).innerHTML = http.responseText;
	}
}

function getRadioValue(pTerm) {
        radios = document.getElementsByName(pTerm);
        for (i = 0; i < radios.length; i++) {
			if (radios[i].checked) 
				return radios[i].value;
			
		}

		return 12;
}

function handleAddtoBasket(pName,pTerm){
	var term;
	term = getRadioValue(pTerm);
	window.location = "https://www.internet.gen.tr/c/hsignup.php?pt=&plan="+pName+"&term="+term;
}

function handleAddtoBasketN(pName){
	var planName;
	planName = getRadioValue(pName);
	window.location = "https://www.internet.gen.tr/c/hsignup.php?pt=&plan="+planName+"&term=12";
}

