var p_array = new Array();
p_array[0] = new Array();
p_array[0][0] = 1;

var p_taksit_array = new Array();
p_taksit_array[0] = new Array();
p_taksit_array[0][0] = 1;

function check_membership() {
	cook_logged = "";
	cook_name = "";
	cook_surname = "";
	cook_email = "";
	mysessionid = "";

	get_userinfo_from_cookie();

	var username = cook_name + " " + cook_surname;
	if ( cook_logged == "true" ) {
		SupportOrgWithInfo('tr', document.referrer, true, username, cook_email, '', '', '' );
	}
}


function commentBodyCounter(event) {
	limit = 2000;
	if ($$('#comment_body textarea')[0].value.length > limit) {
		Event.stop(event);
	}
}

function check_member_form(form) {
	if (form.frmeposta.value.length == 0) {
		alert("Lütfen e-posta adresinizi girin!");
		form.frmeposta.focus();
		return false;
	}

	str=form.frmeposta.value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

	if (!filter.test(str)) {
		alert("Lütfen e-posta adresinizi kontrol ediniz!");
		form.frmeposta.focus();
		return false;
	}

	if (form.frmpass.value.length == 0) {
		alert("Lütfen þifrenizi girin!");
		form.frmpass.focus();
		return false;
	}

	return true;
}

function check_kampanya_form(form) {
	if (form.frmkampanya.value.length == 0) {
		alert("Lütfen kampanya kodunu girin!");
		form.frmkampanya.focus();
		return false;
	}
	return true;
}

function open_pop_up (theLabel,windowName,features) {
	window.open(theLabel,windowName,features);
}

///// ana sayfa haberci fonksiyonlari
function emailCheck(str) {
    var i,ch;
    if (str.length == 0) return(false);
    //check for invalid chars
    for (i=0;i<str.length;i++){
        if (
            (str.charCodeAt(i) < 48 || str.charCodeAt(i) >  57)  &&   // "0"-"9" 'un disinda ise
            (str.charCodeAt(i) < 64 || str.charCodeAt(i) >  90)  &&   // "@" ve "A"-"Z" disinda ise
            (str.charCodeAt(i) < 97 || str.charCodeAt(i) > 122)  &&   // "a"-"z" disinda ise
            (str.charCodeAt(i) < 45 || str.charCodeAt(i) >  46)  &&   // "-" ve "." disinda ise
            (str.charCodeAt(i)!=95 )                                  // "_" dan farkli ise
        ) return (false)
    }

    if ( str.length < 5 )               return(false)
    if ( str.indexOf(" ")  > -1 )       return(false)
    if ( str.indexOf(".")  < 1 )        return(false)
    if ( str.indexOf("@")  < 1 )        return(false)
    if ( str.indexOf("@.") > -1 )       return(false)
    if ( str.indexOf("..") > -1 )       return(false)
    if ( str.indexOf("@") != str.lastIndexOf("@") ) return(false)
    if ( str.length - str.lastIndexOf(".") - 1 <= 1 ) return(false)
    return(true)
}

function stringTrim(str){
	return true;
}

function send_form2() {
	if (document.form_haberci.email.value=="") {
		alert("Lutfen bir e-posta adresi giriniz")
		return;
	}

	if (emailCheck(document.form_haberci.email.value) == false) {
		alert("Lutfen e-posta adresinin dogru oldugundan emin olunuz!");
		return;
	}

	document.form_haberci.submit();
}

function kampanya_haber() {
	kampanya_haberdar_et = window.open("_kampanya_haberdar_et", "kampanya_haberdar_et", "width=200,height=200,status=no,toolbar=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no,alwaysRaised=yes,left=145,top=40");
	document.kamform.submit();
}

function change_display(katman) {
	if(document.getElementById(katman).style.display == "block") {
		document.getElementById(katman).style.display = "none"
	} else if (document.getElementById(katman).style.display == "none") {
		document.getElementById(katman).style.display = "block"
	}
}

//For colored products... #FIX ME: This is used only where color selection exists for products.
var agt = navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
var is_nav  = ((agt.indexOf("mozilla")!=-1) && (agt.indexOf("spoofer")==-1)
                && (agt.indexOf("compatible") == -1) && (agt.indexOf("opera")==-1)
                && (agt.indexOf("webtv")==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
						(agt.indexOf("; nav") != -1)) );
var is_nav5 = (is_nav && (is_major == 5));
var is_nav5up = (is_nav && (is_major >= 5));

var is_ie   = (agt.indexOf("msie") != -1);
var is_ie3  = (is_ie && (is_major < 4));
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie4up  = (is_ie  && (is_major >= 4));
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);

var is_opera = (agt.indexOf("opera") != -1);

function RenkSec(color) {
	if (is_nav){
		document.forms["sepete_ekle"].urun.value = color;
		document.forms["hizli_sat_al"].urun.value = color;
	}else{
		document.getElementById("sepetekle_urun").value = color;
		document.getElementById("hizlial_urun").value = color;
	}
}

function calculateThumbSize(width, height) {
	var aspect = width/height;

	if (aspect > 1) { // horizontal
		if (width >= 150) {
			width = 140;
			height = width/aspect;
		}
	} else { // vertical
		if (height >= 150) {
			height = 140;
			width = height*aspect;
		}
	}

	var dimensions = [];
	dimensions[0] = width;
	dimensions[1] = height;

	return dimensions;
}

function mouseOverStar() {
	for(i=1; i <= this.starNum; i++) {
		stars[i].className = 'starsHover';
	}
	for(i=this.starNum + 1; i <= 5; i++) {
		stars[i].className = 'stars';
	}
}

function mouseOutStar() {
	for(i=1; i<=5; i++) {
		stars[i].className = 'stars';
	}
}

function showVoteResults(vote_result) {
	for(i=1; i<=vote_result; i++) {
		stars[i].className = 'starsHover';
	}
}


/*
 * vote
 *
 * Uses Prototype Ajax methods
 *
 * Parameters:
 * 	- p_id: Product id
 * 	- vote_value: The value the user vote with
 *
 * Returns:
 * 	- True: if voting is successfull
 * 	- False: otherwise
 * 
 */
function vote(p_id, vote_value, wait_text, result_text) {
	new Ajax.Request('_urun_sayfasi', {
		method: 'post',
		parameters: {pid: p_id, vote: vote_value},
		onCreate: function () {
			$('vote_result').update(wait_text);
			if (navigator.appName == 'Microsoft Internet Explorer') {
				$('vote_result').setStyle({
					display: 'inline',
					color: '#993333'
				});
			} else {
				$('vote_result').setStyle({
					display: 'table-cell',
					color: '#993333'
				});
			}
		},
		onSuccess: function (response) {
			var result = eval("(" + response.responseText + ")");
			$('vote_result').update(result['message']);
			if (navigator.appName == 'Microsoft Internet Explorer') {
				$('vote_result').setStyle({
					display: 'inline',
					color: '#336699'
				});
			} else {
				$('vote_result').setStyle({
					display: 'table-cell',
					color: '#336699'
				});
			}
			if ($('v1') && $('v2')) {
				$('v1').update(result['vote_count']);
				$('v2').update(result['vote_sum']);
			} else {
				var temp = result_text.split('%s');
				result_text = temp[0] + "<div id='v1'>" + result['vote_count'] + "</div>" + temp[1] + "<div id='v2'>" + result['vote_sum'] + "</div>" + temp[2];
				$('vote_info').update(result_text);
			}
			showVoteResults(result['vote_result']);
			// Create a global variable for vote_results
			product_vote_result = result['vote_result'];
		}
	});
}

function showVoteResults(vote_result) {
	stars = new Array();

	for(i=1; i<=5; i++) {
		stars[i] = document.getElementById('star' + i);
		stars[i].onmouseover = mouseOverStar;
		stars[i].onmouseout = mouseOutStar;
		stars[i].starNum = i;
		if (i <= vote_result)
			stars[i].className = 'starsHover';
	}
}

function xmlSetSizeEqual() {
	var melodi_height = $('melodi').getStyle('height');
	var oyun_height = $('oyun').getStyle('height');

	if (melodi_height < oyun_height) {
		$('melodi').setStyle({
			height: oyun_height
		});
	} else {
		$('oyun').setStyle({
			height: melodi_height
		});
	}
}

function checkCommentSize(error) {
	if ($$('#comment_title input')[0].value.length == 0 || $$('#comment_body textarea')[0].value.length == 0) {
		alert(error);
	} else {
		document.new_comment.submit();
	}
}

/*
 * calculateScreenSize
 *
 * calculates the whole width and size of page inside the browser
 * window and returns it as an [x, y] array
 *
 */
function calculateScreenSize() {
var sizes = {}

	sizes["width"] = document.body.scrollWidth || 1024
	sizes["height"] = document.body.scrollHeight || 768
	sizes["inner_width"] = document.body.offsetWidth || window.innerWidth || 1024
	sizes["inner_height"] = document.body.offsetHeight || window.innerHeight || 768

	return sizes
}
